/*
 * led.c
 *
 *  Created on: May 11, 2023
 *      Author: zhulijun
 */
#include "my_inc.h"
#include <stdio.h>


static void led_on(uint8_t num);
static void led_off(uint8_t num);
static void led_flow(void);



led_t led =
{
	led_on,
	led_off,
	led_flow,
};


/**
  * @brief  Turn on the led
  * @param  num where can be (led_b、led_g、led_r) to select which led.
  * @retval None.
  */
static void led_on(uint8_t num)
{
	switch(num)
	{
		case led_b:
			HAL_GPIO_WritePin(LED_BLUE_GPIO_Port, LED_BLUE_Pin, GPIO_PIN_RESET);
			break;
		case led_g:
			HAL_GPIO_WritePin(LED_GREEN_GPIO_Port, LED_GREEN_Pin, GPIO_PIN_RESET);
			break;
		case led_r:
			HAL_GPIO_WritePin(LED_RED_GPIO_Port, LED_RED_Pin, GPIO_PIN_RESET);
			break;
		default:
			printf("error led_num\r\n");
	}
}

/**
  * @brief  Turn off the led
  * @param  num where can be (led_b、led_g、led_r) to select which leds.
  * @retval None.
  */
static void led_off(uint8_t num)
{
	switch(num)
	{
		case led_b:
			HAL_GPIO_WritePin(LED_BLUE_GPIO_Port, LED_BLUE_Pin, GPIO_PIN_SET);
			break;
		case led_g:
			HAL_GPIO_WritePin(LED_GREEN_GPIO_Port, LED_GREEN_Pin, GPIO_PIN_SET);
			break;
		case led_r:
			HAL_GPIO_WritePin(LED_RED_GPIO_Port, LED_RED_Pin, GPIO_PIN_SET);
			break;
		default:
			printf("error led_num\r\n");
	}
}

/**
  * @brief  Let all the leds to flow in order.
  * @param  None.
  * @retval None.
  */
static void led_flow(void)
{
	HAL_GPIO_WritePin(LED_BLUE_GPIO_Port, LED_BLUE_Pin, GPIO_PIN_RESET);
	HAL_Delay(500);
	HAL_GPIO_WritePin(LED_BLUE_GPIO_Port, LED_BLUE_Pin, GPIO_PIN_SET);

	HAL_GPIO_WritePin(LED_GREEN_GPIO_Port, LED_GREEN_Pin, GPIO_PIN_RESET);
	HAL_Delay(500);
	HAL_GPIO_WritePin(LED_GREEN_GPIO_Port, LED_GREEN_Pin, GPIO_PIN_SET);

	HAL_GPIO_WritePin(LED_RED_GPIO_Port, LED_RED_Pin, GPIO_PIN_RESET);
	HAL_Delay(500);
	HAL_GPIO_WritePin(LED_RED_GPIO_Port, LED_RED_Pin, GPIO_PIN_SET);
}
